home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / DirectInput / DIConfig / cd3dsurf.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-08  |  3.8 KB  |  170 lines

  1. #include "common.hpp"
  2. #include "id3dsurf.h"
  3.  
  4. class CDirect3DSurface8: public IDirect3DSurface8Clone
  5. {
  6. public:
  7.     CDirect3DSurface8();
  8.     ~CDirect3DSurface8();
  9. /*    ULONG AddRef();
  10.     HRESULT QueryInterface(REFIID iid, void **ppvObject);
  11.     ULONG Release();*/
  12.  
  13.     // IUnknown methods
  14.     STDMETHOD(QueryInterface) (REFIID  riid, 
  15.                                                          VOID  **ppvObj);
  16.     STDMETHOD_(ULONG,AddRef) ();
  17.     STDMETHOD_(ULONG,Release) ();
  18.  
  19.     // IBuffer methods
  20.     STDMETHOD(SetPrivateData)(REFGUID riid, 
  21.                                                         CONST VOID   *pvData, 
  22.                                                         DWORD   cbData, 
  23.                                                         DWORD   dwFlags);
  24.  
  25.     STDMETHOD(GetPrivateData)(REFGUID riid, 
  26.                                                         VOID   *pvData, 
  27.                                                         DWORD  *pcbData);
  28.  
  29.     STDMETHOD(FreePrivateData)(REFGUID riid);
  30.  
  31.     STDMETHOD(GetContainer)(REFIID riid, 
  32.                                                     void **ppContainer);
  33.  
  34.     STDMETHOD(GetDevice)(IDirect3DDevice8 **ppDevice);
  35.  
  36.     // IDirect3DSurface8 methods
  37.     STDMETHOD_(D3DSURFACE_DESC, GetDesc)();
  38.  
  39.     STDMETHOD(LockRect)(D3DLOCKED_RECT  *pLockedRectData, 
  40.                                             CONST RECT      *pRect, 
  41.                                             DWORD            dwFlags);
  42.  
  43.     STDMETHOD(UnlockRect)();
  44.  
  45.     BOOL Create(int iWidth, int iHeight);
  46.  
  47. /*    HRESULT GetDevice(IDirect3DDevice8** ppDevice);
  48.     HRESULT SetPrivateData(REFGUID refguid, CONST void* pData, DWORD SizeOfData, DWORD Flags);
  49.     HRESULT GetPrivateData(REFGUID refguid, void* pData, DWORD* pSizeOfData);
  50.     HRESULT FreePrivateData(REFGUID refguid);
  51.     HRESULT GetContainer(REFIID riid, void** ppContainer);
  52.  
  53.     D3DSURFACE_DESC GetDesc();
  54.     HRESULT LockRect(D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags);
  55.     HRESULT UnlockRect();*/
  56.  
  57. private:
  58.     int m_iRefCount;
  59.     BYTE *m_pData;
  60.     D3DSURFACE_DESC m_Desc;
  61. };
  62.  
  63. CDirect3DSurface8::CDirect3DSurface8() : m_pData(NULL), m_iRefCount(1)
  64. {
  65. }
  66.  
  67. CDirect3DSurface8::~CDirect3DSurface8()
  68. {
  69.     delete[] m_pData;
  70. }
  71.  
  72. BOOL CDirect3DSurface8::Create(int iWidth, int iHeight)
  73. {
  74.     m_pData = new BYTE[iWidth * iHeight * 4];
  75.     if (!m_pData) return FALSE;
  76.  
  77.     m_Desc.Format = D3DFMT_A8R8G8B8;
  78.     m_Desc.Type = D3DRTYPE_SURFACE;
  79.     m_Desc.Usage = 0;
  80.     m_Desc.Pool = D3DPOOL_SYSTEMMEM;
  81.     m_Desc.Size = iWidth * iHeight * 4;
  82.     m_Desc.MultiSampleType = D3DMULTISAMPLE_NONE;
  83.     m_Desc.Width = iWidth;
  84.     m_Desc.Height = iHeight;
  85.     return TRUE;
  86. }
  87.  
  88. STDMETHODIMP_(ULONG) CDirect3DSurface8::AddRef()
  89. {
  90.     return ++m_iRefCount;
  91. }
  92.  
  93. STDMETHODIMP CDirect3DSurface8::QueryInterface(REFIID iid, void **ppvObject)
  94. {
  95.     return E_NOINTERFACE;
  96. }
  97.  
  98. STDMETHODIMP_(ULONG) CDirect3DSurface8::Release()
  99. {
  100.     if (!--m_iRefCount)
  101.     {
  102.         delete this;
  103.         return 0;
  104.     }
  105.     return m_iRefCount;
  106. }
  107.  
  108. /////////// Dummy implementations ///////////////
  109.  
  110. STDMETHODIMP CDirect3DSurface8::SetPrivateData(REFGUID riid, CONST VOID *pvData, DWORD cbData, DWORD dwFlags)
  111. {
  112.     return S_OK;
  113. }
  114.  
  115. STDMETHODIMP CDirect3DSurface8::GetPrivateData(REFGUID riid, VOID *pvData, DWORD *pcbData)
  116. {
  117.     return S_OK;
  118. }
  119.  
  120. STDMETHODIMP CDirect3DSurface8::FreePrivateData(REFGUID riid)
  121. {
  122.     return S_OK;
  123. }
  124.  
  125. STDMETHODIMP CDirect3DSurface8::GetContainer(REFIID riid, void **ppContainer)
  126. {
  127.     return S_OK;
  128. }
  129.  
  130. STDMETHODIMP CDirect3DSurface8::GetDevice(IDirect3DDevice8 **ppDevice)
  131. {
  132.     return S_OK;
  133. }
  134.  
  135. // Required implementation
  136.  
  137. STDMETHODIMP_(D3DSURFACE_DESC) CDirect3DSurface8::GetDesc()
  138. {
  139.     return m_Desc;
  140. }
  141.  
  142. // Assume the entire surface is being locked.
  143. STDMETHODIMP CDirect3DSurface8::LockRect(D3DLOCKED_RECT* pLockedRect, CONST RECT* pRect, DWORD Flags)
  144. {
  145.     pLockedRect->Pitch = m_Desc.Width * 4;
  146.     pLockedRect->pBits = m_pData;
  147.     return S_OK;
  148. }
  149.  
  150. STDMETHODIMP CDirect3DSurface8::UnlockRect()
  151. {
  152.     return S_OK;
  153. }
  154.  
  155.  
  156.  
  157. IDirect3DSurface8 *GetCloneSurface(int iWidth, int iHeight)
  158. {
  159.     CDirect3DSurface8 *pSurf = new CDirect3DSurface8;
  160.  
  161.     if (!pSurf) return NULL;
  162.     if (!pSurf->Create(iWidth, iHeight))
  163.     {
  164.         delete pSurf;
  165.         return NULL;
  166.     }
  167.  
  168.     return (IDirect3DSurface8*)pSurf;
  169. }
  170.